<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>试听管理页面</title>
<meta name="renderer" content="webkit">	
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
<meta name="apple-mobile-web-app-status-bar-style" content="black">	
<meta name="apple-mobile-web-app-capable" content="yes">	
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/table.css">
</head>
<body>
<div class="content-head">悦宝园会员管理系统</div>
<div class="content-main">
	<div class="side-nav" ms-controller="navBar">
		<ul class="nav-item">
			<li><a href="main.html" class="nav-item-front nav-item-add">首页</a></li>
			<li ms-for="el in @navTitleArr">
				<a href="javascript:;" class="nav-item-front">{{el.par}}</a>
				<dl class="nav-item-child">
					<dd ms-for="($index, ex) in el.child"><a ms-attr='{href: el.href[$index]}'>{{ex}}</a></dd>
				</dl>
			</li>
		</ul>
	</div>
	<div class="content bg-gray" ms-controller="main">
		<div class="tab-content">
			<div class="tab-item">
				<div class="sub-main">
					<p class="sub-title"><i>试听管理</i></p>
					<div class="search-area">
						<div class="search-block">
							<span class="search-name">试听时间：</span>
							<div class="search-input">
								<select id="year">
									<option value="2019">2019</option>
									<option value="2020">2020</option>
									<option value="2021">2021</option>
								</select>
								<span class="search-name" style="padding: 0 10px;">年</span>
								<select id="month">
									<option value="1">1</option>
									<option value="2">2</option>
									<option value="3">3</option>
									<option value="4">4</option>
									<option value="5">5</option>
									<option value="6">6</option>
									<option value="7">7</option>
									<option value="8">8</option>
									<option value="9">9</option>
									<option value="10">10</option>
									<option value="11">11</option>
									<option value="12">12</option>
								</select>
								<span class="search-name" style="padding: 0 10px;">月</span>
							</div>
						</div>
						<div class="search-block">
							<a href="javascript:;" class="search-btn" ms-on-click="searchData()">搜索</a>
						</div>
					</div>
					<div class="table-area">
						<div class="table-head">
							<span class="col-5">序号</span>
							<span class="col-15">宝宝姓名</span>
							<span class="col-10">出生日期</span>
							<span class="col-20">月龄</span>
							<span class="col-20">试听课程</span>
							<span class="col-10">所属顾问</span>
							<span class="col-20">操作</span>
						</div>
						<div class="table-body">
							<div class="table-line" ms-for="（i，el） in @allData">
								<div class="col-padding col-border col-inline col-center col-5">{{i+1}}</div>
								<div class="col-padding col-border col-inline col-center col-15">{{el.name}}</div>
								<div class="col-padding col-border col-inline col-center col-10">{{el.month}}</div>
								<div class="col-padding col-border col-inline col-center col-20">{{el.date}}</div>
								<div class="col-padding col-border col-inline col-center col-20">{{el.classFullName}}</div>
								<div class="col-padding col-border col-inline col-center col-10">{{el.cc}}</div>
								<div class="col-padding col-border col-inline col-center col-20" ms-html="@editBtn(el)">
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="mask hide" id="mask"></div>
		<div class="mask-content hide" id="content" style="width: 450px; height: 280px;">
			<p class="mask-title">试听信息</p>
			<div class="import-block">
				<span class="import-name">试听姓名：</span>
				<div class="import-input">{{@sName}}</div>
			</div>
			<div class="import-block">
				<span class="import-name">所属顾问：</span>
				<div class="import-input">{{@sCc}}</div>
			</div>
			<div class="import-block">
				<span class="import-name">成交金额：</span>
				<div class="import-input"><input type="text" maxlength="5" id="money" style="width: 100px;"></div>
			</div>
			<div class="import-block">
				<span class="import-name"></span>
				<div class="import-input">
					<a href="javascript:;" class="import-btn" id="reMemberConfirm">确认</a>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="js/jq.js"></script>
<script src="js/avalon.js"></script>
<script src="js/main.js"></script>
<script>
(function() {
	var allData = baseFunc.getStorageData("schedule"),
		clickDate,
		clickClass,
		clickName;
	var vm = avalon.define({
		$id: "main",
		allData: [],
		sName: "",
		sCc: "",
		searchData: function() {
			var year = $("#year option:selected").val(),
				month = $("#month option:selected").val(),
				tempArr = [];
				finalArr = [];
			for (var i = 0; i < allData.length; i++) {
				var cDate = allData[i].date.split("-");
				if(cDate[0] == year && cDate[1] == month) {
					tempArr.push(allData[i]);
				}
			};

			for (var n = 0; n < tempArr.length; n++) {
				var date = tempArr[n]["date"];
				var infos = tempArr[n]["info"];
				for (var p = 0; p < infos.length; p++) {
					var students = infos[p].students;
					var className = infos[p].classFullName;
					if(students) {
						for (var k = 0; k < students.length; k++) {
							if(students[k].type == "reMember") {
								students[k].date = date;
								students[k].classFullName = className;
								finalArr.push(students[k]);
							}
						};
					}
				};
			};
			this.allData = finalArr; 
		},
		isMoney: function(name, cc, date, className) {
			this.sName = clickName = name;
			this.sCc = cc;
			clickDate = date;
			clickClass = className;
			$("#mask").removeClass("hide");
			$("#content").removeClass("hide");
		},
		editBtn: function(el) {
			if(el.isMoney) {
				return '<span>已成交</span>';
			}
			return '<a href="javascript:;" class="audition-editBtn" ms-on-click="isMoney(el.name, el.cc, el.date, el.classFullName)"></a>';
		}
	});

	$("#mask").click(function() {
		$("#mask").addClass("hide");
		$("#content").addClass("hide");
	});
	
	$("#reMemberConfirm").click(function() {
		$("#mask").addClass("hide");
		$("#content").addClass("hide");
		if($.trim($("#money").val()).length == 0) {
			baseFunc.alert("请输入金额");
			return;
		}
		var isBreak = false;
			stop = 0;
		for (var i = 0; i < allData.length; i++) {
			if(isBreak) {
				break;
			}
			if(allData[i].date == clickDate) {
				for (var n = 0; n < allData[i]["info"].length; n++) {
					if(isBreak) {
						break;
					}
					if(allData[i]["info"][n].classFullName == clickClass) {
						for (var k = 0; k < allData[i]["info"][n]["students"].length; k++) {
							if(allData[i]["info"][n]["students"][k].name == clickName) {
								allData[i]["info"][n]["students"][k].isMoney = true;
								allData[i]["info"][n]["students"][k].price = $("#money").val();
								isBreak = true;
								stop = i;
								break;
							}
						};
					}
				};
			}
		};
		baseFunc.editStorageData("schedule", allData[stop]);
		baseFunc.locationSkip("audition.html");
	});
})();
</script>
</body>
</html>